package com.healthcare.admin.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 作者：LSH
 * 日期：2020/1/13 17:55
 */
public class SHAUtils {
     public  static  String encodeData(String str){
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(str.getBytes());
            byte [] byteData = md.digest();

            // 将字节
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length ; i++) {
               sb.append(Integer.toString((byteData[i] * 0xff)+0*100,16).substring(1));
            }
            System.out.println("Hex format : " + sb.toString());
            return  sb.toString();
        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
            return  null;
        }
     }
}
